<template>
	<view class="login-container">
		<view class="entry-box">
			<view class="phoneNum inputbox">
				<text class="iconfont icon-icon-test24" />
				<text>手机号码</text>
				<input type="text" v-model:value="userLoginVo.telephone" placeholder="请输入手机号" />
				</input>
			</view>
			<view class="password inputbox">
				<text class="iconfont icon-icon-test33" />
				<text>验证码</text>
				<input type="password" v-model:value="userLoginVo.captcha" placeholder="请输入验证码" />
			</view>
			<view class="middle_button" @click="sendCaptcha" :disabled="sending">{{sendTime}}</view>
			<view class="password inputbox">
				<text class="iconfont icon-icon-test26" />
				<text>新密码</text>
				<input type="password" v-model:value="userLoginVo.password" placeholder="请输入新密码" />
			</view>
			<!-- 登陆按钮、忘记密码、我已阅读 -->
			<view class="middle_button" @click="toLogin">立即找回</view>
		</view>
	</view>
	<!-- 		<view class="wrapper">
			<view class="input-content">
				<view class="cu-form-group"
					style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
					<view class="title">手机号</view>
					<input type="number" v-model="userLoginVo.telephone" placeholder="请输入手机号" maxlength="11"
						data-key="telephone" @input="inputChange" />
				</view>
				<view class="cu-form-group"
					style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
					<text class="title">验证码</text>
					<input type="number" v-model="userLoginVo.captcha" placeholder="请输入验证码" maxlength="6"
						data-key="captcha" @input="inputChange" @confirm="toLogin" />
					<view class="middle_button" @click="sendCaptcha" :disabled="sending">{{sendTime}}</view>
				</view>
				<view class="cu-form-group"
					style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
					<text class="title">设置密码</text>
					<input type="password" v-model="userLoginVo.password" placeholder="请设置新密码"
						placeholder-class="input-empty" maxlength="20" minlength="6" data-key="password"
						@input="inputChange" @confirm="toLogin" />
				</view>
			</view>
			<view class="middle_button" @click="toLogin">立即找回</view>
		</view>
	</view> -->
</template>

<script>
	export default {
		data() {
			return {
				userLoginVo: {
					telephone: '',
					captcha: '',
					password: ''
				},
				sending: false,
				sendTime: '获取验证码',
				count: 60,
				logining: false
			}
		},

		methods: {
			sendCaptcha() {
				if (!this.userLoginVo.telephone) {
					uni.showToast({
						title: '请输入手机号',
						icon: "error"
					});
				} else if (this.userLoginVo.telephone.length != 11) {
					uni.showToast({
						title: '请输入正确的手机号',
						icon: "error"
					});
				} else {
					this.$myRequest({
						url: '/sendCaptcha',
						data: {
							telephone: this.userLoginVo.telephone
						}
					}).then(r => {
						if (r.data.code == 200) {
							console.log(r);
							this.countDown();
						}
					})
				}
			},
			countDown() {
				const {
					count
				} = this;
				if (count === 1) {
					this.count = 60;
					this.sending = false;
					this.sendTime = '获取验证码'
				} else {
					this.count = count - 1;
					this.sending = true;
					this.sendTime = count - 1 + '秒后重新获取';
					setTimeout(this.countDown.bind(this), 1000);
				}
			},
			inputChange(e) {
				const key = e.currentTarget.dataset.key;
				this[key] = e.detail.value;
			},
			navBack() {
				uni.navigateBack();
			},


			navTo(url) {
				uni.navigateTo({
					url
				})
			},
			toLogin() {
				if (!this.userLoginVo.telephone) {
					uni.showToast({
						title: '请输入手机号',
						icon: "error"
					});
				} else if (this.userLoginVo.telephone.length != 11) {
					uni.showToast({
						title: '请输入正确的手机号',
						icon: "error"
					});
				} else if (!this.userLoginVo.captcha) {
					uni.showToast({
						title: '请输入验证码',
						icon: "error"
					});
				} else if (!this.userLoginVo.password) {
					uni.showToast({
						title: '请输入密码',
						icon: "error"
					});
				} else {
					this.$myRequest({
						url: '/login/forgetPwd',
						data: this.userLoginVo,
						method: 'post'
					}).then(r => {
						if (r.data.code == 200) {
							// 将用户id存储在本地缓存中
							uni.showToast({
								title: "找回成功，即将返回登陆",
								icon: "success"
							})
							// 返回登录页面
							setTimeout(function() {
								uni.navigateTo({
									url: '/pages/public/login'
								})
							}, 1500)
						}
					});
				}
			}
		}
	}
</script>

<style lang='scss'>
	.header {
		padding: 120rpx 70rpx 0rpx 70rpx;
		margin-bottom: 40rpx;

		image {
			width: 130rpx;
			height: 130rpx;
			margin-bottom: 30rpx;
			border-radius: 25rpx;
			box-shadow: 2rpx 2rpx 10rpx 1rpx #C8C7CC;
		}

		.titl {
			font-size: 40rpx;
		}
	}

	.entry-box {
		padding: 50rpx 70rpx 0rpx 70rpx;

		.inputbox {
			margin-bottom: 20rpx;

			text:nth-child(2) {
				font-size: 30rpx;
				color: #C0C0C0;
			}

			input {
				line-height: 40rpx;
				height: 90rpx;
				border-bottom: 1px solid #dadada;
				-border: 1px solid red;
			}
		}

		.middle_button {
			margin: 0 auto;
			margin-top: 50rpx;
			margin-bottom: 20rpx;
			width: 600rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			border-radius: 20rpx;
			color: white;
			font-size: 35rpx;
			background: $main-colorB;
		}

		.forgetPsw {
			color: #818082;
			width: 600rpx;
			margin: 0 auto;
			font-size: 25rpx;
			margin-top: 20rpx;
			margin-bottom: 20rpx;
		}

		.read {
			color: #9f9ea2;
			width: 600rpx;
			margin: 0 auto;
			font-size: 25rpx;

			text {
				color: $main-colorB;
			}
		}
	}

	.footer {
		width: 750rpx;
		-border: 1px solid red;
		text-align: center;
		position: fixed;
		bottom: 30rpx;
		font-size: 30rpx;
		color: #6b6b6b;
	}
</style>
